package org.nowcoder.leetcode.DP;

/**
 * Title  : 122. Best Time to Buy and Sell Stock II
 * Source : https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/description/
 * Author : XrazYang
 * Date   : 2023-12-22
 */

public class LeetCode_122 {
    //贪心策略
    public int maxProfit(int[] prices) {
        int ans = 0;
        int n = prices.length;
        for (int i = 1; i < n; ++i) {
            ans += Math.max(0, prices[i] - prices[i - 1]);
        }
        return ans;
    }
}
